package com.gaofeng.day12;

import java.util.Random;

public class Role {
    private  String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }


    public  void atack(Role role){
        Random rd = new Random();
        int hurt = rd.nextInt(20) + 1;
        int remainBlood = role.getBlood() - hurt;
        remainBlood = Math.max(0,remainBlood);
        role.setBlood(remainBlood);
        System.out.println(this.getName() + "打了"+role.getName() +"一下,造成了"+hurt+ "点伤害，"+role.getName()+"还剩余"+remainBlood+"血量");
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }


    /**
     * 获取
     * @return blood
     */
    public int getBlood() {
        return blood;
    }

    /**
     * 设置
     * @param blood
     */
    public void setBlood(int blood) {
        this.blood = blood;
    }

    public String toString() {
        return "Role{name = " + name + ", hurt = " + ", blood = " + blood + "}";
    }
}
